﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PraemicTask
{
    class Program
    {

        static void Main(string[] args)
        {
            DoWork();
            //Task.Factory.StartNew(() => DoWork());

            Console.WriteLine("Before Download");

            var result = Download("http://mic.am").ContinueWith((t)=> 
            {
                Console.WriteLine("Waiting for HTML...");

                Console.WriteLine((t.Result.Length * 2.0 / 1024) + "KB");
            });

            Console.WriteLine("Done");

            Console.ReadKey();
        }

        static async Task DoWork()
        {
            await Task.Factory.StartNew(()=> Thread.Sleep(3000));
            Console.WriteLine("Hi Mamikon!");
        }

        static async Task<string> Download(string url)
        {
            var client = new HttpClient();

            Console.WriteLine("Before Task Started");

            Task<string> getHtmlTask = client.GetStringAsync(url);

            Console.WriteLine("After Task Started");

            string html = await getHtmlTask;
            //var html = getHtmlTask.Result;

            Console.WriteLine("Downloding");

            return html;
        } 

        
    }
}
